import Vue from 'vue'
import Vuex from 'vuex'
import favorite from './modules/favorite'
import { getStorage, setStorage, removeStorage } from '@/utils/storage.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    currentCity: {
      city: '上海',
      id: 'AREA|dbf46d32-7e76-1196'
    },
    selectCommunity: null,
    userToken: getStorage('token')
  },
  mutations: {
    setCom (state, payload) {
      state.selectCommunity = payload
    },
    removeCom (state) {
      state.selectCommunity = null
    },
    setCity (state, payload) {
      state.currentCity = payload
    },
    setToken (state, payload) {
      setStorage('token', payload)
      state.userToken = payload
    },
    removeToken (state) {
      removeStorage('token')
      state.userToken = null
    }
  },
  actions: {},
  getters: {},
  modules: {
    favorite
  }
})
